#ifndef PROJECTCREATOR_H
#define PROJECTCREATOR_H


#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
#include <QVector>
#include <QSet>
#include <QString>
#include <QStringList>
#include <QFileInfo>
#include <string>
#include <iostream>
#include <fstream>
#include <QTextStream>
#include <cmath>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QDateTime>
#include <QVariant>
#include <QDebug>
#include <QMessageBox>
#include "imagesort.h"

using namespace std;

class ProjectCreator
{
public:
    ProjectCreator();
    ProjectCreator(const QString &file, const QString &dir, const QDateTime &start,
                   const int &interval, const bool &included);
    QString getExpFile() { return expFileName;}
    ~ProjectCreator();

private:
    // Retrieve all image files in 'dir' and save to the
    bool getFiles(string dir);
    // Process experiment output file, get related experiment
    // header info, create database for this experiment and
    // store info to the database.
    void processExpFile();
    // Create database for the experiment and name it to include
    // today's date.
    void setupDatabase();
    // Create table for the database of the experiment
    void setupTable();
    void closeDatabase();
    // Save each row of the input experiment to database
    void save(QStringList &list);
    // This method will update and return image filename.
    void updateFileName();
   // Return all time intervals given a pdn
    void getTime(const QString &pdn, QStringList &result);
    // Update database with image file name
    void update(const QString &pdn, QStringList &time, QStringList &files);
    // Update individual row
    void updateRow(const QString &pdn, const QString &time, const QString &file);
    // Create project file used for later usage.
    void createProj();

    QVector<QString> files; // A list of files in the current directory, which contains the pictures and experiment file
    QString expFile;        // Input experiment
    QString dir;            // Directory of image files
    QDateTime start;        // Start time of experiment
    int interval;           // Interval of images taken
    bool included;          // Indicate whether images contain initial time
    QFile projFile;         // Project file to be output
    QString projInfo;       // Project header info
    QSqlDatabase db;        // Created database
    QSet<QString> pdns;    // QSet of unique pdn
    QSet<QString> families;  // QSet of unique family

    QString expFileName;
    ImageSort *imgSort;     // To sort image file based on created time.
};

#endif // PROJECTCREATOR_H
